# -*- coding: UTF-8 -*-
import threading
from multiprocessing import Queue
# 水池
class Pool:
    # 初始化水池的长宽高
    def __init__(self, width, length, pool_height, fluid_height, x_coordinate, y_coordinate, z_coordinate,
                 max_fluid_height, min_fluid_coordinate, total_flow):
        self.width = width
        self.length = length
        self.pool_height = pool_height
        self.fluid_height = fluid_height
        self.x_coordinate = x_coordinate
        self.y_coordinate = y_coordinate
        self.z_coordinate = z_coordinate
        self.max_fluid_height = max_fluid_height
        self.min_fluid_height = min_fluid_coordinate
        self.total_flow = total_flow



    # 初始化水池长，宽，高写到配置文件中
    # 加水按照  m³/h  单位
    #  换算水位 计算质量
    # plus fluid

    # 初始化水位高度
    def increase_fluid(self, q: Queue):
        increase_flow = q.get(True)
        self.total_flow += increase_flow * 1
        print('increasePool total_flow is %f'% self.total_flow)
        while True:
            if self.fluid_height < self.max_fluid_height:
                self.fluid_height += self.total_flow / (self.width * self.length)
                print('increasePool fluid height is %f ' % self.fluid_height)
            else:
                print("the flow_height level over secrety line,please stop increase,")
                break

    # flow 是两个水泵的流量加起来之和  计算时间是1秒
    def decrease_fluid(self, q: Queue):
        decrease_flow = q.get(True)
        self.total_flow -= decrease_flow*1
        print('decreasePool total_flow is %f' % self.total_flow)
        # 判断当前水位
        while True:
            if self.fluid_height > self.min_fluid_height:
                self.fluid_height -= self.total_flow / (self.width * self.length)
                print('decreasePool fluid height is %f ' % self.fluid_height)
            else:
                print("the flow_height level low ,please increase fluid,decrease fluid stoped!!!")
                break
